<template>
  <div class="alarmConfiguration zy-content">
    <!-- 搜索 -->
    <search :columns="searchData" @getSearch="getSearch(arguments)" :span="4"></search>
    <div class="alarmConfiguration">
      <div class="list-layout mt16">
        <!-- 批量删除 批量导出  批量导入 下载模板 新增-->
        <div class="btns clear">
          <span class="title">工装出入库记录</span>
        </div>
        <!-- 表格 -->
        <div class="tableContent">
          <Table
            class="resizable-table"
            border
            @on-column-width-resize="(a,b,c,d)=>{onColumnWidthResize(a,b,c,d,'orderAdjustmentDeviceInfo')}"
            :columns="orderAdjustmentDeviceInfoList"
            ellipsis
            stripe
            :data="dataArr"
          ></Table>
        </div>
        <!-- 分页 -->
        <div class="pageWrap mt16">
          <pageLeftTitle :total="total" :selected="delIds.length" />
          <Page
            :total="total"
            :page-size="pageSize"
            :page-size-opts="pageSizeOption"
            :current="pageNum"
            @on-change="changePageNum"
            @on-page-size-change="changePageSize"
            show-sizer
            show-total
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import recursion from "@/util/recursion";
import { findOrgByToken } from "@/api/index.js";
import search from "@/components/curd/searchList.vue";
import toggleTableOperation from "@/mixins/toggleTableOperation";

export default {
  name: "moldOutAndIn",
  components: { search },
  mixins: [toggleTableOperation],
  data() {
    return {
      searchData: [
        {
          title: "操作类型",
          key: "operationType",
          type: "select",
          dicData: [
            { label: "出库", value: "0" },
            { label: "入库", value: "1" }
          ]
        },
        {
          title: "工装编号",
          key: "moldCode"
        },
        {
          title: "状态",
          key: "status",
          type: "select",
          dicData: [
            { label: "完成", value: "0" },
            { label: "驳回", value: "1" }
          ]
        },
        {
          title: "申请时间",
          key: "time",
          type: "daterange"
        }
      ],
      columns: [
        {
          title: "操作类型",
          key: "operationType",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true,
          render: (h, params) => {
            return h("div", params.row.operationType == 0 ? "出库" : "入库");
          }
        },
        {
          title: "工装编号",
          key: "moldCode",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "工装名称",
          key: "moldName",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "功能位置",
          key: "functionalLocation",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "库区",
          key: "reservoirArea",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "库位",
          key: "warehouseLocation",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "出库类型",
          key: "outboundType",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "状态",
          key: "status",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true,
          render: (h, params) => {
            return h("div", params.row.status == 0 ? "完成" : "驳回");
          }
        },
        {
          title: "出入库人",
          key: "personnel",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "申请时间",
          key: "applicationTime",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "审核人",
          key: "applicant",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "审核时间",
          key: "auditTime",
          minWidth: 100,
          align: "center",
          resizable: true,
          tooltip: true
        },
        {
          title: "驳回原因",
          key: "reasonRejection",
          minWidth: 100,
          align: "center",
          tooltip: true,
          resizable: true,
          tooltip: true
        }
      ],
      formItem: {},
      allCheck: false,
      loading: false,
      create: false,
      searchParams: {},

      pageNum: 1,
      pageSize: 10,
      total: 0,
      dataArr: [],
      pageSizeOption: [10, 20, 30, 40],

      delIds: [],
      selection: [],
      orgList: []
    };
  },
  mounted() {
    this.getTableColumnsWidth(this.columns, "orderAdjustmentDeviceInfo");
    this.searchList();
    this.getOrgList();
    // this.getTableColumnsWidth(this.columns);
  },
  methods: {
    // filterData(arr, code) {
    //     let temp = [];
    //     let callback = function (nowArr, code) {
    //         for (let item of nowArr) {
    //             if (item.code === code) {
    //                 temp.unshift(item.code);
    //                 callback(arr, item.parentId);
    //                 break;
    //             } else {
    //                 if (item.children && item.children.length) {
    //                     callback(item.children, code);
    //                 }
    //             }
    //         }
    //     };
    //     callback(arr, code);
    //     return temp;
    // },
    getSearch(params) {
      this.searchParams = JSON.parse(JSON.stringify(params[0]));
      if (this.searchParams.time) {
        this.searchParams.applicationTimeStart = this.searchParams.time[0];
        this.searchParams.applicationTimeEnd = this.searchParams.time[1];
        delete this.searchParams.time;
      }
      this.pageNum=1;
      this.searchList();
    },
    change(val) {
      this.formItem.mlocationCode = val;
      this.formItem.mlocation = this.$refs["cascader"].displayRender;
    },
    //分页
    changeNum() {
      this.pageNum = 1;
      this.searchList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.searchList();
    },
    changePageNum(val) {
      this.pageNum = val;
      this.searchList();
    },

    //查询列表
    searchList() {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      };
      for (let key in this.searchParams) {
        if (this.searchParams[key]) {
          this.$set(params, key, this.searchParams[key]);
        }
      }
      this.axios({
        method: "post",
        url: "/dms/moldApplicationRecords/getMoldApplicationList",
        data: params
      }).then(res => {
        if (res.code === 200) {
          this.dataArr = res.data.records;
          this.total = res.data.total;
        }
      });
    },
    getOrgList() {
      let params = {
        level: 0
      };
      findOrgByToken(params).then(res => {
        if (res.code === 200) {
          const obj = {
            label: "name",
            value: "code",
            children: "children"
          };
          this.orgList = recursion.convertTree(res.data, obj);
        } else {
          this.$Message.warning({
            content: res.msg,
            duration: 6,
            closable: true
          });
        }
      });
    }
  }
};
</script>
      
<style scoped lang="scss">
.ivu-input-number {
  width: -webkit-fill-available;
}
</style>